class Solution:
    def numberOfArrays(self, differences: List[int], lower: int, upper: int) -> int:
        s = 0
        min_s = 0
        max_s = 0
        for d in differences:
            s += d 
            min_s = min(min_s, s)
            max_s = max(max_s, s)
        return max(upper-lower-max_s+min_s+1,0)